var calculate = function(key, op, value){
    var val = data[key] || '';
    if(val.indexOf("[json]") === 0){
        try{
            var v = val.substr("[json]".length);
            v = JSON.parse(v);
            var arr = [];
            for(var i in v){
                arr.push(v[i]);
            }
            val = arr.join(",");
        } catch (e) {
        }
    }
    switch(op){
        case "等于":
            return val == value
        case "大于":
            return val > value
        case "大于等于":
            return val >= value
        case "小于":
            return val < value
        case "小于等于":
            return val <= value
        case "不等于":
            return val != value
        case "包含":
            return val.indexOf(value) > -1
        case "不包含":
            return val.indexOf(value) == -1
    }
    return false;
};


/**
 * 前段使用
 * @param attrs
 * @param str
 */
var calculate_macro = function (str) {
    var expression = (str || "").replace(/\[\s*(.+?)\s*\]/g, function (a,b) {
        return "\"" + ($("[title=" + b + "]").val() || "") + "\"";
    });
    expression = expression
        .replace(/（/g, "(")
        .replace(/）/g, ")");

    try{
        var val = eval(expression);
        if(isNaN(val)){
            return "";
        }
        if(val === null){
            return "";
        }
        return val + "";
    } catch (e) {
        return "";
    }
};

var DATE = function (str) {
    str = str.replace(/-/g,'/');
    try{
       return Math.floor(new Date(str).getTime() / (1000 * 60 * 60 * 24));
    } catch (e) {
        return "";
    }
};

var NOW = function () {
    return new Date().getTime() / 1000;
};

var TO_PERCENT = function (key) {
    return (key * 100.00).toFixed(2) + "%";
}


